package com.kgcx.common.bean;

import com.kgcx.common.utils.ApplicationUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel(value = "返回数据对象")
@Data
public class ReturnData<E> {
    public static final String OK = "0";

    public static final ReturnData NO_PERMISSION = new ReturnData("-98", "没有权限");


    public static ReturnData getResult() {
        ReturnData returnData = new ReturnData<>();
        return returnData;
    }


    public ReturnData() {
        this.code = OK;
        this.msg = "请求成功!";
        this.source = ApplicationUtils.getApplicationName();
    }

    public ReturnData(E data) {
        this.code = OK;
        this.msg = "请求成功!";
        this.data = data;
        this.source = ApplicationUtils.getApplicationName();

    }

    public ReturnData(String code, String message) {
        this.code = code;
        this.msg = message;
        this.source = ApplicationUtils.getApplicationName();

    }

    public ReturnData(E data, String code, String message) {
        this.code = code;
        this.msg = message;
        this.data = data;
        this.source = ApplicationUtils.getApplicationName();

    }

    public ReturnData(E data, Integer pages, String code, String message) {
        this.code = code;
        this.msg = message;
        this.data = data;
        this.pages = pages;
        this.source = ApplicationUtils.getApplicationName();

    }

    public ReturnData(E data, Integer pages, Integer total, String code, String message) {
        this.code = code;
        this.msg = message;
        this.data = data;
        this.pages = pages;
        this.total = total;
        this.source = ApplicationUtils.getApplicationName();

    }

    public ReturnData(E data, Integer pages, String code, String message, Integer pageNum) {
        this.code = code;
        this.msg = message;
        this.data = data;
        this.pages = pages;
        this.pageNum = pageNum;
        this.source = ApplicationUtils.getApplicationName();

    }

    /**
     * 返回数据
     */
    @ApiModelProperty(value = "数据", position = 9999)
    private E data;
    /**
     * 返回CODE
     */
    @ApiModelProperty(value = "状态码", position = 0, example = OK)
    private String code;
    /**
     * 返回信息
     */
    @ApiModelProperty(value = "状态消息", position = 1, example = "请求成功!")
    private String msg;
    /**
     * 总页数
     */
    @ApiModelProperty(value = "总页数", position = 3, example = "100")
    private Integer pages;
    /**
     * 总记录数
     */
    @ApiModelProperty(value = "总条数", position = 2, example = "1000")
    private Integer total;
    /**
     * 页码
     */
    @ApiModelProperty(value = "页码", position = 4, example = "1")
    private Integer pageNum;
    /**
     * 来源
     */
    @ApiModelProperty(value = "来源", position = 5, example = "system")
    private String source;

    public boolean success() {
        return OK.equals(this.code);
    }
}
